using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using DAL;
using Utility;

public partial class Admin_LoaiSPList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData1();
        }
    }
    private void LoadData1()
    {
        Criteria cri = new Criteria();
        int total = 0;
        if (txt_tlsp.Text != "")
        {
            cri.add(Condition.AND, tbLoaiSP.tbLoaiSPColumns.TenLoaiSP.ToString(), Condition.LIKE, txt_tlsp.Text);
        }
        tbLoaiSP.tbLoaiSPCollection loaispcollection = tbLoaiSPBUS.Get(cri.Criter, Pager.CurrentIndex, Pager.PageSize, tbLoaiSP.tbLoaiSPColumns.IDLoaiSP.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = loaispcollection;
        Repeater1.DataBind();
        Pager.ItemCount = total;
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        LoadData1();
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            tbLoaiSP tlsp = (tbLoaiSP)e.Item.DataItem;
            HyperLink hyp_tlsp = (HyperLink)e.Item.FindControl("hyp_tlsp");

            Literal lit_mlsp = (Literal)e.Item.FindControl("lit_mlsp");
            HiddenField hf_id = (HiddenField)e.Item.FindControl("hf_id");


            lit_mlsp.Text = tlsp.IDLoaiSP.ToString();
            hf_id.Value = tlsp.IDLoaiSP.ToString();

            hyp_tlsp.Text = tlsp.TenLoaiSP.ToString();


            hyp_tlsp.NavigateUrl = "LoaiSPList.aspx";


            HyperLink hpl_Edit = (HyperLink)e.Item.FindControl("hpl_Edit");
            hpl_Edit.NavigateUrl = "LoaiSPUpdate.aspx?id=" + tlsp.IDLoaiSP.ToString();


        }

    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData1();
    }
    protected void lbt_Xoa_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_Xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
            if (cb_Xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
                tbLoaiSP  lsp = tbLoaiSPBUS.GetByID(id);
                tbLoaiSPBUS.Delete_LoaiSP(id);
            }
        }
        Response.Redirect(Request.RawUrl);
    }
}
